package com.xinzhitong.www.mapper;

import com.xinzhitong.www.pojo.TempAccount;
import com.xinzhitong.www.pojo.User;
import com.xinzhitong.www.provider.UpdateSQLProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * user表相关操作
 *
 * @author 徐鑫
 */
@Repository
public interface UserMapper {

    @Select("select * from user where username=#{username}")
    User selectByUsername(@Param("username") String username);

    @Insert("insert into user(username, password) values(#{user.username}, #{user.password})")
    Integer insertUser(@Param("user") User user);

    @Insert("insert into user(username, password, role) values(#{username}, #{password}, #{role})")
    Integer insertUserWithRole(User user);

    @UpdateProvider(type = UpdateSQLProvider.class, method = "getSQLOfUpdate")
    Integer updateUser(@Param("table") String table, @Param("source") User user, @Param("condition") String condition);

    @Update("update user set password=#{password} where username=#{username}")
    Integer updateUserByTempAccount(TempAccount tempAccount);

    @Update("update user set last_login_time=#{lastLoginTime} where username=#{username}")
    void updateLastLoginTime(User user);

}
